package com.jinghong.registerlogin.service.impi;

import com.jinghong.registerlogin.mapper.QuestionMapper;
import com.jinghong.registerlogin.model.pojo.Question;
import com.jinghong.registerlogin.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName:QuestionServiceimpi
 * Package:com.jinghong.registerlogin.service.impi
 * Description:
 *
 * @Author: 寻月君子
 * @CreatTime:2024/5/18 21:48
 * Version:1.0
 */
@Service
public class QuestionServiceimpi implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;

    //增
    /**新增题目*/
    @Override
    public void insert(Question question) {
        //为系统注入创建和更改时间
        question.setUpdateTime(LocalDateTime.now());
        question.setCreatTime(LocalDateTime.now());
        questionMapper.insert(question);
    }


    /**批量添加题目*/
    @Override
    public void bulkInsert(List<Question> questions) {

        questions.forEach(question -> {
            //根据内容和题目类型去重
            Question question1 =  questionMapper.getByContentAndType(question.getContent(), question.getType());
            if (question1 != null){
                questions.remove(question);
            }
        });
        questionMapper.bulkInsert(questions);
    }



    //删
    /**删除题目*/
    @Override
    public void delete(List<Integer> ids) {
        questionMapper.delete(ids);
    }



    //改
    /**更改题目信息*/
    @Override
    public void update(Question question) {
        question.setUpdateTime(LocalDateTime.now());
        questionMapper.update(question);
    }



    //查
    /*题目的条件查询*/
    @Override
    public List<Question> select(Integer userId, String content, Short type, Integer scorce, LocalDateTime begain, LocalDateTime end) {
        return questionMapper.select(userId,content,type,scorce,begain,end);
    }


    @Override
    public Question getById(Integer id) {
        return questionMapper.getById(id);
    }

    @Override
    public Question getByContentAndType(String content, Short type) {
        return questionMapper.getByContentAndType(content,type);
    }

    @Override
    public List<Question> bulkGet(List<Integer> ids) {
        return questionMapper.bulkGet(ids);
    }

    @Override
    public void bulkUpdate(List<Question> questions) {
        questionMapper.bulkUpdate(questions);
    }
}
